#!/bin/bash
#############################################
#date:2015-05-01
#hawk
#############################################

SOFT_DIR=/data/software
HOST="/etc/sysconfig/network"
OLDHOSTNAME=`grep "HOSTNAME" $HOST |awk -F "=" '{print $2}'`

rm -rf "/data/lost+found"

mkdir $SOFT_DIR

sed -i "s/HOSTNAME=$OLDHOSTNAME/HOSTNAME=$1/g" /etc/sysconfig/network
echo "127.0.0.1  $1  "  >>/etc/hosts
/bin/hostname $1


> /etc/sysconfig/i18n
cat >>/etc/sysconfig/i18n<<EOF
LANG="en_US.UTF8"  
LANGUAGE="zh_CN.GB18030:zh_CN.GB2312:zh_CN"  
SUPPORTED="zh_CN.GB18030:zh_CN:zh:en_US.UTF-8:en_US:en"  
SYSFONT="lat0-sun16"
EOF
source /etc/sysconfig/i18n
echo "export LANG=en_US.UTF8" >> /etc/profile
source /etc/profile


#alias
sed -i "8 s/^/alias vi='vim'/" /root/.bashrc
sed -i "s/alias cp='cp -i'/alias cp='cp'/" /root/.bashrc
source /root/.bashrc


echo 'HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S " ' >>/etc/profile
echo "export HISTTIMEFORMAT" >>/etc/profile
source /etc/profile


#epel
yum install -y java-1.7.0-openjdk-devel.x86_64
yum install -y redhat-lsb-core.x86_64
yum install -y dos2unix.x86_64
yum install -y wget sudo zip unzip
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
rm -rf epel-release-6-8.noarch.rpm

#yum 
yum install -y ntp
yum install -y vim
yum -y install bind-utils
yum install -y telnet
yum install -y mysql
yum install -y rsync


#set cron
echo '*/5 * * * * /usr/sbin/ntpdate time.windows.com >/dev/null 2>&1' >>/var/spool/cron/root
service crond restart

#set ulimit
echo "ulimit -SHn 102400" >> /etc/rc.local
cat >> /etc/security/limits.conf << EOF
*           soft   nofile       65535
*           hard   nofile       65535
EOF
ulimit -n 65535

cat /dev/null >/etc/issue 
cat /dev/null >/etc/issue.net 
cat /dev/null >/etc/motd
yum install -y sysstat


#disable ipv6
cat << EOF
+--------------------------------------------------------------+
|         === Welcome to Disable IPV6 ===                      |
+--------------------------------------------------------------+
EOF
echo "alias net-pf-10 off" >> /etc/modprobe.conf
echo "alias ipv6 off" >> /etc/modprobe.conf
/sbin/chkconfig --level 35 ip6tables off
echo "ipv6 is disabled!"

#disable selinux
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config 
echo "selinux is disabled,you must reboot!"

#vim
sed -i "8 s/^/alias vi='vim'/" /root/.bashrc
source /root/.bashrc
echo 'syntax on' > /root/.vimrc
cp /etc/ssh/sshd_config /etc/ssh/sshd_config-$(date +%F).bak
#ssh_cf="/etc/ssh/sshd_config" 
#sed -i -e '74 s/^/#/' -i -e '76 s/^/#/' $ssh_cf
#sed -i "s/#Port 22/Port 51303/" $ssh_cf
#sed -i "s/#UseDNS yes/UseDNS no/" $ssh_cf
#sed -i '/#PermitEmptyPasswords no/cPermitEmptyPasswords yes' $ssh_cf 


#zabbix

#client
#sed -i -e '44 s/^/#/' -i -e '48 s/^/#/' $ssh_cf
#service sshd restart
#echo "ssh is init is ok.............."

#chkser
#tunoff services
#--------------------------------------------------------------------------------
cat << EOF
+--------------------------------------------------------------+
|         === Welcome to Tunoff services ===                   |
+--------------------------------------------------------------+
EOF
#---------------------------------------------------------------------------------
for i in `ls /etc/rc3.d/S*`
do
              CURSRV=`echo $i|cut -c 15-`
echo $CURSRV
case $CURSRV in
          crond | network |sshd | syslog  )
      echo "Base services, Skip!"
      ;;
      *)
          echo "change $CURSRV to off"
          chkconfig --level 235 $CURSRV off
          service $CURSRV stop
      ;;
esac
done
echo "service is init is ok.............."

source /etc/sysconfig/i18n
